﻿@using IterationLife.Extensions.EasyUI
@using Util
@using Util.Ui
@model IterationLife.PlatformBackEnd.AppServices.Dtos.FootballTeachings.CourseDto
@{
    var x = @Html.EasyUi();
}
<style type="text/css">
    .course-option {
        background-color: #696969;
        color: #ffffff;
        cursor: pointer;
        padding: 7px;
        margin-right: 5px;
        margin-top: 5px;
        float: left;
    }

        .course-option:hover {
            background-color: #adff2f;
            color: #000000;
        }
</style>
<script type="text/javascript">

    var save_after = function () {
        $.easyui.closeDialog();
    }

    Array.prototype.removeByValue = function (val) {
        for (var i = 0; i < this.length; i++) {
            if (this[i] === val) {
                this.splice(i, 1);
                break;
            }
        }
    }

    var delete_courseCategory = function (divObject, id) {
        var getExcludeIds = function () {
            var onclick = $("#dialogButtonsBtn_courseCategory").attr("onclick");
            var excludeIdsStr = onclick.match(/excludeIds=(\S*)'/)[1];
            if (!excludeIdsStr)
                return [];
            return excludeIdsStr.split(',');
        }
        var excludeIds = getExcludeIds();
        excludeIds.removeByValue(id);
        $("#dialogButtonsBtn_courseCategory").attr("onclick", "$.easyui.dialog({ title: '选择分类', buttons: 'dialogButtons_courseCategory', url: '/FootballTeachings/CourseCategory/DialogIndex?excludeIds=" + excludeIds + "' })");
        $(divObject).remove();
        var courseCategriseDivs = $("#dd_courseCategorise_data").children("div");
        for (var i = 0; i < courseCategriseDivs.length; i++) {
            var textHtml = $(courseCategriseDivs[i]).html();
            $(courseCategriseDivs[i]).html(textHtml.replace(/(\[[^\[]*\])/g, "[" + i + "]"));
        }
    }

    var delete_playerPosition = function (divObject, id) {
        var getExcludeIds = function () {
            var onclick = $("#dialogButtonsBtn_playerPosition").attr("onclick");
            var excludeIdsStr = onclick.match(/excludeIds=(\S*)'/)[1];
            if (!excludeIdsStr)
                return [];
            return excludeIdsStr.split(',');
        }
        var excludeIds = getExcludeIds();
        excludeIds.removeByValue(id);
        $("#dialogButtonsBtn_playerPosition").attr("onclick", "$.easyui.dialog({ title: '选择位置', buttons: 'dialogButtons_playerPosition', url: '/FootballTeachings/playerPosition/DialogIndex?excludeIds=" + excludeIds + "' })");
        $(divObject).remove();
        var playerPositionsDivs = $("#dd_playerPositions_data").children("div");
        for (var i = 0; i < playerPositionsDivs.length; i++) {
            var textHtml = $(playerPositionsDivs[i]).html();
            $(playerPositionsDivs[i]).html(textHtml.replace(/(\[[^\[]*\])/g, "[" + i + "]"));
        }
    }

</script>
<div class="divForm">
    <div class="formtitle">课程管理</div>
    @using (x.Form("form").AddClass("form").Action("/FootballTeachings/course/save").Begin())
    {
        <dl>
            <dt>@Html.LabelFor(t => t.Name)</dt>
            <dd>
                @x.TextBox(t => t.Name)
            </dd>
        </dl>
        <dl>
            <dt>@Html.LabelFor(t => t.Difficulty)</dt>
            <dd>
                @x.Combox(t => t.Difficulty).Width(100)
            </dd>
        </dl>
        <div class="line"></div>
        <dl>
            <dt>@Html.LabelFor(t => t.Banner)</dt>
            <dd style="width:180px;">
                @Html.Ui().Attachment().SingleEdit(t => t.Banner, Model.Banner)
            </dd>
        </dl>
        <div class="line"></div>
        <dl style="width: 100%; height: 125px;">
            <dt>@x.DialogButton("选择分类", $"/FootballTeachings/CourseCategory/DialogIndex?excludeIds={Model.CourseCategories.Select(t => t.Id).Join()}").Buttons("dialogButtons_courseCategory").Id("dialogButtonsBtn_courseCategory")</dt>
            <dd id="dd_courseCategorise_data" style="width: 80%;">
                @for (var i = 0; i < Model.CourseCategories.Count; i++)
                {
                    <div onclick="delete_courseCategory(this,'@(Model.CourseCategories[i].Id)')">
                        <input type="text" name="CourseCategories[@(i)].Id" value="@(Model.CourseCategories[i].Id)" hidden />
                        <input type="text" name="CourseCategories[@(i)].Name" value="@(Model.CourseCategories[i].Name)" hidden />
                        <span class="course-option">@(Model.CourseCategories[i].Name)</span>
                    </div>
                }
            </dd>
        </dl>
        <div class="line"></div>
        <dl style="width: 100%; height: 125px;">
            <dt>@x.DialogButton("选择位置", $"/FootballTeachings/playerPosition/DialogIndex?excludeIds={Model.PlayerPositions.Select(t => t.Id).Join()}").Buttons("dialogButtons_playerPosition").Id("dialogButtonsBtn_playerPosition")</dt>
            <dd id="dd_playerPositions_data" style="width: 80%;">
                @for (var i = 0; i < Model.PlayerPositions.Count; i++)
                {
                    <div onclick="delete_playerPosition(this,'@(Model.PlayerPositions[i].Id)')">
                        <input type="text" name="PlayerPositions[@(i)].Id" value="@(Model.PlayerPositions[i].Id)" hidden />
                        <input type="text" name="PlayerPositions[@(i)].Name" value="@(Model.PlayerPositions[i].Name)" hidden />
                        <span class="course-option">@(Model.PlayerPositions[i].Name)</span>
                    </div>
                }
            </dd>
        </dl>
        <div class="line"></div>
        <dl>
            <dt>@Html.LabelFor(t => t.SortId)</dt>
            <dd>
                @x.TextBox(t => t.SortId)
            </dd>
        </dl>
        @Html.HiddenFor(t => t.ActionNumber)
        @Html.HiddenFor(t => t.ParticipationNumber)
        @Html.HiddenFor(t => t.CreationTime)
        @Html.HiddenFor(t => t.CreatorId)
        @Html.HiddenFor(t => t.LastModificationTime)
        @Html.HiddenFor(t => t.LastModifierId)
        @Html.HiddenFor(t => t.IsDeleted)
        @Html.HiddenFor(t => t.Version)
        @Html.HiddenFor(t => t.Id)
        @Html.AntiForgeryToken()
    }
</div>
<div id="dialogButtons">
    @x.Button("保 存").Icon("icon-ok").Width(90).Submit("", "save_after")
    @x.DialogButton("关 闭").Icon("icon-cancel").Width(90).CloseDialog()
</div>